import random

# 生成一个1到100之间的随机数
number = random.randint(1, 100)
print("I have chosen a number between 1 and 100.")

# 初始化变量
a = ""
min_value = 1
max_value = 100

while not a.isdigit() or int(a)<min_value or int(a) >max_value:
    a = input("Enter a number between 1 and 100: ")

# 将输入转换为整数
a = int(a)

while a != number:
    if a < number:
        print("Too low")
        min_value = a + 1
    else:
        print("Too high")
        max_value = a - 1

    while True:
        a = input(f"Please enter a number between {min_value} and {max_value}: ")
        if a.isdigit() and min_value <= int(a) <= max_value:
            a = int(a)
            break
    else:
        print(f"Please enter a number within the range {min_value} to {max_value}.")

print("Correct!")
print("Thank you for playing!")
